// run: $exec < input
#include <iostream>
#include <cstring>
#include <string>
#include <queue>

struct Node
{
	int x, y;
	Node() {}
	Node(int x, int y) : x(x), y(y) {}
};

int const maxn = 100;
std::string mmap[maxn];
int vis[maxn][maxn];
int vis1[maxn][maxn];
int dy[4] = {0, 0, -1, 1};
int dx[4] = {1, -1, 0, 0};
int num[maxn][maxn][maxn][maxn];
int n, m;

Node node[maxn];
Node start, end;

bool check(Node a)
{
	return (a.x >= 0 && a.x < n && a.y >= 0 && a.y < m && mmap[a.x][a.y] != '#');
}

void get(char c, int& u, int& v)
{
	if (c == '-') { u = 2; v = 4; }
	else if (c == '|') { u = 0; v = 2; }
	else if (c == '.') { u = 0; v = 1; }
	else { u = 0; v = 4; }
}

void bfs()
{
	std::queue<Node> q;
	q.push(start);
	vis[start.x][start.y] = 1;
	Node tmp, now;
	while (!q.empty()) {
		tmp = q.front(); q.pop();
		int u, v;
		get(mmap[tmp.x][tmp.y], u, v);
		for (int i = u; i < v; i++) {
			now.x = tmp.x + dx[i];
			now.y = tmp.y + dy[i];
			if (check(now)) {
				num[tmp.x][tmp.y][now.x][now.y] = 1;
				if (!vis[now.x][now.y]) {
					vis[now.x][now.y] = 1;
					q.push(now);
				}
			}
		}
	}
	if (vis[end.x][end.y] == 0) {
		std::cout << "I'm stuck!\n";
		return;
	}
	q.push(end);
	while (!q.empty()) {
		tmp = q.front(); q.pop();
		for (int i = 0; i < 4; i++) {
			now.x = tmp.x + dx[i];
			now.y = tmp.y + dy[i];
			if (check(now) && vis1[now.x][now.y] == 0 && num[now.x][now.y][tmp.x][tmp.y]) {
				vis1[now.x][now.y] = 1;
				q.push(now);
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			if (vis[i][j] == 1 && vis1[i][j] == 0) ans++;
	std::cout << ans << "\n";
}

int main()
{
	while (std::cin >> n >> m) {
		memset(vis, 0, sizeof(vis));
		memset(vis1, 0, sizeof(vis1));
		memset(num, 0, sizeof(num));
		for (int i = 0; i < n; i++) {
			std::cin >> mmap[i];
			for (int j = 0; j < m; j++) {
				if (mmap[i][j] == 'S') { start.x = i; start.y = j; }
				if (mmap[i][j] == 'T') { end.x = i; end.y = j; }
			}
		}
		bfs();
	}
}

